# !/usr/bin/python
# -*- coding: utf-8 -*-

# THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),  
# to deal in the Software without restriction, including without limitation  
# the rights to use, copy, modify, merge, publish, distribute, sublicense,  
# and/or sell copies of the Software, and to permit persons to whom the  
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in 
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
# DEALINGS IN THE SOFTWARE.

# config.py
# written by: 
#     Jan Jokela <jan@devion.org>

import os, sys
import ConfigParser

conf_file = os.path.join(os.path.expanduser('~'), '.mediaplex', 'mediaplex.conf')

conf = ConfigParser.ConfigParser()

conf.read(conf_file)

def get_option(_section, _key, type='str'):
    for section in conf.sections():  
        if section == _section:           
            for key in conf.options(section):
                if key == _key: 
                    if type == 'str': return conf.get(section, key)
                    elif type == 'int': return conf.getint(section, key)
                    elif type == 'float': return conf.getfloat(section, key)
                    elif type == 'boolean': return conf.getboolean(section, key)
                    elif type == 'list':
                        if len(conf.get(section, key)) > 1:
                            list = []
                            l = eval(conf.get(section, key))
                            for i in l:
                                list.append[i]
                            return list
                        else: print "mu"
                        
def set_option(section, key, value):
    conf.set(section, key, value)
    
input = get_option('app', 'input', 'str')
